<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class Order extends Model
{
//    绑定表
    protected $table='month_exam_order';
    /**
     * @param $data
     * @return Order|Model
     * 向订单表中添加信息
     */
    public function addOrder($data){
        return $this->create($data);
    }

    /**
     * @return \think\model\relation\HasMany
     * 与订单商品表模型关联
     */
    public function orderGoodsData(){
        return $this->hasMany(OrderGoods::class,'order_id');
    }


    /**
     * @param $orderSn
     * @return bool|int
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 修改订单状态
     */
    public function changeState($orderSn){
//        先查询在save则代表修改
        $order=$this->where('order_sn',$orderSn)->find();
        $order->order_state='1';
        return $order->save();
    }
}
